package com.hjw.junit;

import com.hjw.dao.DVDDaoImp;
import com.hjw.pojo.DVD;

import java.time.LocalDate;
import java.util.Scanner;

/**
 * @author hjwStrart
 * @create 2022-01-14 12:56
 */
public class DVDTest {

    public static void main(String[] args) {
        menu();
    }
    static DVDDaoImp dvdDaoImp = new DVDDaoImp();
    static Scanner scanner= new Scanner(System.in);
    public static void menu(){
        System.out.println("欢迎使用迷你DVD管理器");
        System.out.println("--------------------");
        while(true){

            System.out.println("1.新增DVD");
            System.out.println("2.查看DVD");
            System.out.println("3.删除DVD");
            System.out.println("4.借出DVD");
            System.out.println("5.归还DVD");
            System.out.println("6.退出DVD");
            Integer accept = acceptFromKeyboard();
            switchFun(accept);
        }


    }
    public static Integer acceptFromKeyboard(){
        System.out.print("请选择：");
        int i = scanner.nextInt();
        return i;
    }

    public static void switchFun(Integer accept){
        switch (accept){
            case 1:{
                System.out.println("请输入DVD信息：String name,Double rent");
                System.out.print("请输入DVD名称：");
                String name = scanner.next();
                System.out.print("请输入DVD租金：（使用了包装类必须带小数点）");
                Double rent = scanner.nextDouble();
                System.out.println(dvdDaoImp.addDVD(new DVD(name,0,null,0L,null,rent)) ? "添加成功！" : "添加失败！");
                break;
            }
            case 2: {
                DVD[] dvds = dvdDaoImp.queryAllDVD();
                for (DVD dvd : dvds) {
                    System.out.println(dvd);
                }
                break;
            }
            case 3:{
                System.out.print("请输入你要删除的DVD名称");
                String name = scanner.next();
                System.out.println(dvdDaoImp.deleteDVD(name) ? "删除成功！" : "删除失败！");
                break;
            }
            case 4:{
                System.out.print("请输入要借出的DVD名称");
                String name = scanner.next();
                System.out.print("请输入借出日期(XXXX-xx-xx)");
                String date = scanner.next();
                String[] split = date.split("-");
                Integer year = Integer.parseInt(split[0]);
                Integer month = Integer.parseInt(split[1]);
                Integer day = Integer.parseInt(split[2]);
                LocalDate loanTime = LocalDate.of(year,month,day);
                System.out.println(dvdDaoImp.loanDVD(name, loanTime) ? "借出成功！" : "借出失败！");
                break;
            }
            case 5:{
                System.out.print("请输入要归还的DVD名称");
                String name = scanner.next();
                System.out.print("请输入归还日期(XXXX-xx-xx)");
                String date = scanner.next();
                String[] split = date.split("-");
                Integer year = Integer.parseInt(split[0]);
                Integer month = Integer.parseInt(split[1]);
                Integer day = Integer.parseInt(split[2]);
                LocalDate returnTime = LocalDate.of(year,month,day);
                System.out.println(dvdDaoImp.returnDVD(name, returnTime) ? "归还成功！" : "归还失败！");
                break;
            }
            case 6:
                System.exit(0);break;
            default:
                System.out.println("请输入1~6之内的数字！");break;
        }
    }
}
